#include "Tools/ToolRotateObject.h"

using namespace Ogre;
ToolRotateObject::ToolRotateObject(Ogre::Camera *mCam, Ogre::SceneManager *ScrMgr, Ogre::RaySceneQuery* ray)
{
	objectSelected=false;
	select = new ActionSelectObject(mCam,ScrMgr,ray);
	moveCam = new ActionMoveCamera(mCam);
}

ToolRotateObject::~ToolRotateObject(){}

void ToolRotateObject::updateGraphics(const FrameEvent &evt){

	moveCam->updateGraphics(evt);
}

void ToolRotateObject::mouseMoved(const OIS::MouseEvent &evt){

	if(objectSelected){
	//comprobar q es el scroll
			scale->mouseMoved(evt);
		rotateObject->mouseMoved(evt);
	}
	else
		moveCam->mouseMoved(evt);
}

void ToolRotateObject::mousePressed(const OIS::MouseEvent &evt){
	
	if(!objectSelected){
		if(select->mousePressed(evt)){
			rotateObject = new ActionRotateObject(select->getSelectedNode());
			scale = new ActionScaleObject(select->getSelectedNode());
			objectSelected=true;
		}
	}
	else{
		rotateObject->mousePressed(evt);
		MapEditor::instance()->toolEnded();
		objectSelected=false;
	}
}

void ToolRotateObject::keyPressed(const OIS::KeyEvent &evt){
	
	if(evt.key==OIS::KC_X)
		rotateObject->selectAxis(1);
	if(evt.key==OIS::KC_Y)
		rotateObject->selectAxis(2);
	if(evt.key==OIS::KC_B)
		rotateObject->selectAxis(0);
	if(!objectSelected)
		moveCam->keyPressed(evt);
}
void ToolRotateObject::keyReleased(const OIS::KeyEvent &e){

	if(!objectSelected)
		moveCam->keyReleased(e);
}
